/**
 * 我得OKR 引用JS文件
 */

//初始化页面加载
$(function(){
	pageList(true,1);
});

$("#btn_search").click(function(){
	mui('.mui-popover').popover('toggle');
	$(".mui-backdrop.mui-active").hide();
	$("#serch").hide();
});

function tree(orgCode){
	location.href="tree?orgCode="+orgCode;
}


function pageList(isInit,pageIndex){
	
	var month =document.getElementById("month1").value;
	var year =document.getElementById("year1").value;
	var quarter =document.getElementById("quarter1").value;
	var state =document.getElementById("state1").value;
	var odefinition =document.getElementById("odefinition1").value;
	
	$.ajax({
		url : "../org/okr",
		type : "post",
		dataType : "json",
		data : {"orgCode":orgCode,"emplCode":emplCode,"memberCode":memberCode,"pageIndex":pageIndex,"pageSize":pageSize,"month":month,"year":year,"quarter":quarter,"state":state,"odefinition":odefinition},
		success : function(data){
			
			console.log(data);
			
			if(data == null || data == -1 || data.items.length == 0){
				$("#list").html('<div class="mui-card" style=""><div class="mui-card-footer"><p class="index-status" style="text-align:center; width:100%;margin-top:3%;">暂无信息</p></center></div>');
				return;
			}
			
			if(isInit){
				//加载分页控件
		    	$("#page").page({
					total: data.pagesCount, //总页数
					pageIndex: data.curIndex, //当前页
					pageSize: data.pageSize, //每页显示
					showJump: true, //显示跳转项
					showInfo:true, //是否显示记录信息
					infoFormat: '总共{total}条记录,每页显示{size}条记录,共{count}页' //定义记录信息格式
				}).on("pageClicked", function (event, pageIndex) {
					//分页点击
					pageList(false, pageIndex);
				}).on('jumpClicked', function (event, pageIndex) {
					//跳转点击
					pageList(false, pageIndex);
				});	
			}
			
			$("#list").html("");
			var str = "";  
			$.each(data.items,function(n,value) {
				
				str += '<div class="mui-card" style="">';
				str += '<div class="noba">';
				str += '<div class="mui-card-header" style="border-tottom: none; padding-bottom: 0px;">';
				str += '<span style="float: left;"> <span class="bold">'+value.PERSON_LIABLE_NAME+'</span>';
				str += '&nbsp;&nbsp;&nbsp; <font color="#666666">'+okrTime(value.O_YEAR,value.O_QUARTER,value.O_MONTH)+'</font>';
				str += '</span> <span> <a href="#pop'+n+'"" class="mui-btn mui-btn-primary index-btn-mod"> ';
				str += '<span class="index-func mui-icon mui-icon-gear cfff"></span>';
				str += '</a></span></div>';
				str += '<div class="noba">';
				str += '<div class="mui-card-footer" style="border-top: solid thin #fff; padding-top: 0px; padding-bottom: 2px;">';
				str += '<span style="float: left; color: #6d6d72;">OKR类别：'+oTeam(value.OKR_TYPE)+'</span> <span>所属组织：'+value.OWNER_DEPTNAME+'</span>';
				str += '</div> </div>';
				str += '<div class="mui-card-footer" style="border-bottom: solid thin #ddd; border-top: solid thin #fff; padding-top: 0px; padding-bottom: 2px;">';
				str += '<span style="float: left; color: #6d6d72;">所属团队：'+value.OWNER_TEAMNAME+'</span> <span>职务：'+value.PERSON_LIABLE_POSTNAME+'</span>';
				str += '</div> </div>';
				str += '<div class="mui-card-content">';
				str += '<div class="mui-card-header">';
				str += '<span style="font-weight: bold;">'+value.O_CODE+'</span> ';
				str += '<span style="float: right; font-size: 14px; color: #666;"> ';
				str += '<span class="index-dlink"><a href="../self/krview?uniqueCode='+value.O_UNIQUE_ID_CODE+'">OKR详情</a></span></span>';
				str += '</div> <a href="../self/krview?uniqueCode='+value.O_UNIQUE_ID_CODE+'">';
				str += '<div class="mui-card-content-inner">';
				str += '<p class="index-o-de" style="margin-bottom: 0;">';
				str += '<span style="color: #007aff">定义：</span>' + value.O_DEFINITION;
				str += '</p></div></a></div>';
				str += '<div class="mui-card-footer">';
				str += '<span class="index-status">状态： <span class="index-shenhe">'+oState(value.O_STATE)+'</span>';
				str += '</span> <a href="pingfeno.php"><span>评分：'+oColor(value.O_SCORE_SUPERIOR)+'</span></a>';
				str += '</div><div class="mui-card-footer">';
				str += '<a href="../self/version?uniqueCode='+value.O_UNIQUE_ID_CODE+'">版本号：'+value.VERSION_CODE+' &nbsp;</a> <span style="float: right;">发布时间：'+getTime(value.DELIVERY_TIME)+'</span>';
				str += '</div></div><div id="pop'+n+'" class="mui-popover">';
				str += '<ul class="mui-table-view">';
				str += '<li class="mui-table-view-cell"><center>';
				str += '<a href="../self/review?uniqueCode='+value.O_UNIQUE_ID_CODE+'">过程Review</a>';
				str += '</center></li>';
				str += '<li class="mui-table-view-cell"><center>';
				str += '<a href="../self/score?uniqueCode='+value.O_UNIQUE_ID_CODE+'">评分与总结</a>';
				str += '</center></li>';
				str += '<li class="mui-table-view-cell"><center>';
				str += '<a href="../self/version?uniqueCode='+value.O_UNIQUE_ID_CODE+'">版本信息</a>';
				str += '</center></li>';
				str += '<li class="mui-table-view-cell"><center>';
				str += '<a href="../self/link?uniqueCode='+value.O_UNIQUE_ID_CODE+'">关联OKR</a>';
				str += '</center></li></ul></div>';
			
			});  
			
			$("#list").html(str);
			window.scrollTo(0,0);
		}
	});
}